<template>
	<div>{{ this.convertToLocalTime(release_time) }} </div>
</template>

<script>
import Vue from "vue";
export default {
	props: ["release_time"],
	data() {
		return {};
	},

	methods: {
		// 示例1：格式化时间（同步）
		convertToLocalTime(serverTime) {
			if (serverTime == null) {
				return "";
			}
			if (serverTime == "") {
				return "";
			}
			if (serverTime == undefined) {
				return "";
			}
			if (serverTime == "null") {
				return "";
			}
			if (serverTime == "undefined") {
				return "";
			}
			if (serverTime == "0000-00-00 00:00:00") {
				return "";
			}
			if (serverTime == "1970-01-01 08:00:00") {
				return "";
			}
			if (serverTime.length < 8) {
				return serverTime;
			}
			// 将时间字符串转换为 Date 对象（假定是北京时间）
			const beijingTime = new Date(serverTime.replace(/-/g, "/") + " GMT+0800");

			// 获取电脑的地区设置
			const locale = Intl.DateTimeFormat().resolvedOptions().locale;

			// 根据地区设置格式化时间
			const formattedTime = new Intl.DateTimeFormat(locale, {
				year: "numeric",
				month: "2-digit",
				day: "2-digit",
				hour: "2-digit",
				minute: "2-digit",
				second: "2-digit",
			}).format(beijingTime);

			// console.log(locale, "根据地区设置格式化的时间:", formattedTime);

			// 转换为用户设备所在时区的时间
			return formattedTime;
		},
	},
};
</script>
